﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThanhTu.GNCMedia.KQXS.DataAccess.DO;
using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace ThanhTu.GNCMedia.KQXS.DataAccess.DAL
{
    public class StyleLotteryDAL : BaseDAL
    {
        public StyleLotteryDAL() : base() { }
        public int update(StyleLotteryDO vStyleLotteryDO)
        {
            OracleCommand oraComm = new OracleCommand();
            oraComm.CommandType = CommandType.StoredProcedure;
            oraComm.CommandText = "StyleLottery_PKG.SaveLotteryStyle";
            OracleParameter oraParam = null;

            oraParam = new OracleParameter("IN_SETTING_NAME", OracleDbType.Varchar2);
            oraParam.Value = vStyleLotteryDO.Settingname;
            oraComm.Parameters.Add(oraParam);

            oraParam = new OracleParameter("IN_SETTING_TYPE", OracleDbType.Varchar2);
            oraParam.Value = vStyleLotteryDO.Settingtype;
            oraComm.Parameters.Add(oraParam);

            oraParam = new OracleParameter("IN_POSITION", OracleDbType.Varchar2);
            oraParam.Value = vStyleLotteryDO.Position;
            oraComm.Parameters.Add(oraParam);

            oraParam = new OracleParameter("IN_SETTING_VALUE", OracleDbType.Varchar2);
            oraParam.Value = vStyleLotteryDO.Settingvalue;
            oraComm.Parameters.Add(oraParam);


            oraParam = new OracleParameter("OUTRETURN", OracleDbType.Int32);
            oraParam.Direction = ParameterDirection.Output;
            oraComm.Parameters.Add(oraParam);

            int result = ExecuteNoneQuery(oraComm);

            if (!Convert.IsDBNull(oraComm.Parameters["OUTRETURN"]))
            { result = Convert.ToInt32(oraComm.Parameters["OUTRETURN"].Value.ToString()); }

            oraComm.Dispose();
            oraComm = null;
            oraParam = null;

            return result;
        }

        public DataTable SelectAll()
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "StyleLottery_PKG.GetLotteryStyle";
                OracleParameter oraParam = null;


                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);


                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }
                    }

                    return dt;
                }
            }
        }

        public DataTable getbyPosition(string Position)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "StyleLottery_PKG.GetLotteryStyle_POSITION";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_POSITION", OracleDbType.Varchar2);
                oraParam.Value = Position;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);


                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }
                    }

                    return dt;
                }
            }
        }

    }
}
